package com.qianyucc.blog.model.pojo;

import cn.hutool.core.util.*;
import cn.hutool.crypto.digest.*;
import cn.hutool.setting.*;
import com.qianyucc.blog.global.*;
import com.qianyucc.blog.model.entity.*;
import lombok.*;
import org.springframework.stereotype.*;

import java.util.*;

/**
 * @author lijing
 * @e-mail 1413979079@qq.com
 * @date 2020-04-21 12:10
 * @description 博客的所有配置信息
 */
@Data
@Component
public class Configs {
    /**
     * 通过从数据库中查询到的键值对集合，生成Configs对象
     *
     * @param list 描述配置的键值对集合
     */
    public void fromList(List<ConfigDO> list) {
        for (ConfigDO cdo : list) {
            String k = cdo.getKey();
            String v = cdo.getValue();
            switch (k) {
                case Constants.ConfigKey.NAME:
                    this.name = v;
                    break;
                case Constants.ConfigKey.INTRODUCTION:
                    this.introduction = v;
                    break;
                case Constants.ConfigKey.AVATAR:
                    this.avatar = v;
                    break;
                case Constants.ConfigKey.MOTTO:
                    this.motto = v;
                    break;
                case Constants.ConfigKey.WEBSITES:
                    this.websites = v;
                    break;
                case Constants.ConfigKey.USERNAME:
                    this.username = v;
                    break;
                case Constants.ConfigKey.PASSWORD:
                    this.password = v;
                    break;
                case Constants.ConfigKey.ADMIN_TOKEN:
                    this.adminToken = v;
                    break;
                case Constants.ConfigKey.PEN_NAME:
                    this.penName = v;
                    break;
                case Constants.ConfigKey.BLOG_DESC:
                    this.blogDesc = v;
                    break;
                case Constants.ConfigKey.BLOG_ICON:
                    this.blogIcon = v;
                    break;
                case Constants.ConfigKey.BLOG_NAME:
                    this.blogName = v;
                    break;
                default:
                    break;
            }
        }
    }

    private String name;
    private String introduction;
    private String avatar;
    private String motto;
    private String websites;
    private String username;
    private String password;
    private String adminToken;
    private String blogName;
    private String blogDesc;
    private String blogIcon;
    private String penName;
}
